package com.tedu.pj.common.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

/**
 * <p>
 *
 * </p>
 *
 * @author Song
 * @since 2020/10/20
 */
@Slf4j
@Aspect
@Component
public class SysExceptionAspect {

    @Pointcut("bean(*ServiceImpl)")
    public void pointCut(){}

    @AfterThrowing(pointcut = "pointCut()",throwing = "e")
    public void afterthrowing(JoinPoint jp,Throwable e){
        Class<?> aClass = jp.getTarget().getClass();
        MethodSignature ms=(MethodSignature)jp.getSignature();
        String methodName = ms.getMethod().getName();
        log.error("{}.{} exception msg -> {}", aClass.getName(),methodName,e.getMessage());
    }
}
